﻿using NDF;
using NDF.Reflection;
using NDF.Collections;
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Reflection;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
using System.Data;
using System.Data.SqlClient;

namespace NDF.Test.DataAccess
{
    [TestClass]
    public class DatabaseTest
    {
        [TestMethod]
        public void EntLibDatabaseTest()
        {
            //DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
            //Database db = DatabaseFactory.CreateDatabase("BloggingContext");
            var factory = new DatabaseProviderFactory();
            Database db = factory.Create("BloggingContext");
            DataSet set = db.ExecuteDataSet(CommandType.Text, "SELECT * FROM sys.tables");
            foreach (DataRow row in set.Tables[0].Rows)
            {
                Console.WriteLine(row["name"]);
            }
        }



        [TestMethod]
        public void TestMethod2()
        {
            //foreach (var item in AssemblyHelper.GetAssemblies())
            //{
            //    Console.WriteLine(item.FullName);
            //}
            //this.GetType().


            //foreach (var item in AssemblyHelper.GetAssemblies().SelectMany(assembly => assembly.Modules))
            //{
            //    Console.WriteLine(item.FullyQualifiedName);
            //}

            //Console.WriteLine(MemberTypes.Constructor.HasFlag(MemberTypes.Custom));

            var array = typeof(SqlDatabase).GetAllMembers().Sort((a, b) => StringComparer.CurrentCultureIgnoreCase.Compare(a.Name, b.Name));
            foreach (var m in array)
            {
                Console.WriteLine("class name: {0}, method: {1}", m.DeclaringType.Name, m);
            }
            Console.WriteLine(array.Count());
        }





        [TestMethod]
        public void TestMethod1()
        {
            //Database db = DatabaseFactory.CreateDatabase();

            BindingFlags flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
            Console.WriteLine(flag);
            Console.WriteLine("-----");
            Console.WriteLine(flag.GetType());
            Console.WriteLine("-----");
            Console.WriteLine(flag.Equals(BindingFlags.Public));
            Console.WriteLine(flag.Equals(BindingFlags.NonPublic));
            Console.WriteLine(flag.Equals(BindingFlags.Static));
            Console.WriteLine(flag.Equals(BindingFlags.Instance));
            Console.WriteLine("-----");
            Console.WriteLine(flag.CompareTo(BindingFlags.Public));
            Console.WriteLine(flag.CompareTo(BindingFlags.NonPublic));
            Console.WriteLine(flag.CompareTo(BindingFlags.Static));
            Console.WriteLine(flag.CompareTo(BindingFlags.Instance));
            Console.WriteLine("-----");
            Console.WriteLine(flag == BindingFlags.Public);
            Console.WriteLine(flag == BindingFlags.NonPublic);
            Console.WriteLine(flag == BindingFlags.Static);
            Console.WriteLine(flag == BindingFlags.Instance);
            Console.WriteLine("-----");
            Console.WriteLine((int)flag);
            Console.WriteLine("-----");
            Console.WriteLine((int)BindingFlags.Public);
            Console.WriteLine((int)BindingFlags.NonPublic);
            Console.WriteLine((int)BindingFlags.Static);
            Console.WriteLine((int)BindingFlags.Instance);
        }
    }
}
